import { resolve } from 'path'
import { defineConfig, externalizeDepsPlugin } from 'electron-vite'
import react from '@vitejs/plugin-react'
import cesium from 'vite-plugin-cesium'

export default defineConfig({
  main: {
    plugins: [externalizeDepsPlugin()]
  },
  preload: {
    plugins: [externalizeDepsPlugin()]
  },
  renderer: {
    resolve: {
      alias: {
        '@renderer': resolve(__dirname, 'src/renderer')
      }
    },
    server: {
      host: '0.0.0.0',
      port: 3000,
      proxy: {
        '/api/v1': {
          target: 'http://192.168.1.52:8888',
          rewrite: (path) => {
            return path.replace(/^\/api\/v1/, '')
          }
        },
        '/map': {
          target: 'http://192.168.1.52:8888'
        }
      }
    },
    plugins: [
      react(),
      cesium({
        cesiumBuildPath: resolve(__dirname, 'out/renderer/cesium'), // 关键：确保这里是相对路径
        cesiumBaseUrl: './cesium/' // Electron 访问本地资源时需要相对路径
      })
    ]
  }
})
